/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package explorer;

/**
 *
 * @author Laetitia
 */

import java.awt.Component;
import java.io.File;
import java.io.IOException;
import javax.swing.JLabel;
import javax.swing.JTree;
import javax.swing.filechooser.FileSystemView;
import javax.swing.tree.DefaultTreeCellRenderer;

public class FileRenderer extends DefaultTreeCellRenderer {

    public FileRenderer() {
        super();
    }

    /**
     * 
     * @param tree
     * @param value
     * @param selected
     * @param expanded
     * @param leaf
     * @param row
     * @param hasFocus
     * @return 
     */
    @Override
    public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
        JLabel label = (JLabel) super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
        File file = new File(((FileModel) value).getPath());
        FileSystemView sys = FileSystemView.getFileSystemView();
        label.setText(sys.getSystemDisplayName(file));
        
        label.setIcon(sys.getSystemIcon(file));
        
        return label;
    }
}
